import { useRequest } from 'ahooks'
import request from '../../utils/request'
import { useState } from "react";
export function useTableData ({ tableUrl = '',setTotal,ajaxData }) {
    const [tableData, setTableData] = useState([])
    const [noData,setNoData] = useState(false)
    const getTableDataApi = params => {
        return request({
            url: tableUrl,
            data: params
        })
    }
    const { loading, run } = useRequest(getTableDataApi, {
        manual: true,
        onSuccess: res => {
            setNoData(res.data.length < ajaxData.limit)
            if(res.data.length) {
                setTableData([...tableData,...res.data])
            }
        }
    })
    const getTableData = tableParams => {
        run(tableParams)
    }
    return {
        loading,
        getTableData,
        tableData,
        noData
    }
}
